function serializer(args) {
  if (args.length === 1 && isPrimitive(args[0])) {
    return args[0]
  }
  const obj = {}
  for (let i = 0; i < args.length; i++) {
    obj['key' + i] = args[i]
  }
  return JSON.stringify(obj)
}

function isPrimitive(value) {
  const type = typeof value
  return type === 'boolean' || type === 'number' || type === 'string' || type === 'undefined' || value === null
}
/**
 * 记忆函数
 *
 */
export const memoize = func => {
  if (typeof func !== 'function') {
    throw new TypeError('Expected a function')
  }

  return function (...args) {
    const key = serializer(args)
    const Cache = memoize.Cache || Map
    if (Cache.has(key)) {
      // console.log('0',Cache)
      return Cache.get(key)
    }
    const result = func.apply(this, args)
    // console.log('1',Cache)
    Cache.set(key, result)
    return result
  }
}
memoize.Cache = new Map()
